<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_DatasourceInfo"></title>
    <script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
    <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
    <style>

        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 300px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

    </style>
</head>
<body>
    <div id="toolbar" class="panel panel-primary">
        <div class='panel-heading'>
            <h5 class='panel-title text-center' data-i18n="resources.title_DatasourceInfo"></h5></div>
        <div class='panel-body content'>
            <div class='panel'>
                <div class='input-group'>
                    <span class='input-group-addon' data-i18n ="resources.text_Datasources"></span>
                    <select id='datasourcesSelect' class='form-control'></select>
                </div>
            </div>
            <input type="button" class="btn btn-default" data-i18n ="[value]resources.btn_query" 
            onclick="datasourcesPrint()"/>
        </div>
    </div>
    <div id="map"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script>
    let map,
        baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-world/rest/maps/World Map/zxyTileImage.png?z={z}&x={x}&y={y}",
        dataUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/data-world/rest/data";
    let attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
       " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
    map = new mapboxgl.Map({
        container: 'map',
        style: {
            "version": 8,
            "sources": {
                "raster-tiles": {
                    "attribution": attribution,
                    "type": "raster",
                    "tiles": [baseUrl],
                    "tileSize": 256
                }
            },
            "layers": [{
                "id": "simple-tiles",
                "type": "raster",
                "source": "raster-tiles",
            }]
        },
        center: [0, 0],
        zoom: 2
    });
    map.addControl(new mapboxgl.NavigationControl(), 'top-left');
    map.addControl(new mapboxgl.supermap.LogoControl({ link: "https://iclient.supermap.io" }), 'bottom-right');

    map.on("load", function () {
        dataSourcesService();
    });

    function dataSourcesService() {
        new mapboxgl.supermap.DatasourceService(dataUrl).getDatasources(function (serviceResult) {
        const datasourcesSelect = document.getElementById("datasourcesSelect");
        const datasourceNames = serviceResult.result.datasourceNames;
        for (let i = 0, len = serviceResult.result.datasourceNames.length; i < len; i++) {
            datasourcesSelect.options[i] = new Option(datasourceNames[i], datasourceNames[i]);
            }   
        });
    };

    //打印数据源信息
    function datasourcesPrint(){
    const datasourceName = datasourcesSelect.value;
    new mapboxgl.supermap.DatasourceService(dataUrl).getDatasource(datasourceName, function (serviceResult) {
        let innerHTML = "(" + resources.text_datasourceInfoPrint + ")" + "<br><br>";
            innerHTML += "coordUnit：" + JSON.stringify(serviceResult.result.datasourceInfo.coordUnit, null, 2) + "<br>";
            innerHTML += "description:" + JSON.stringify(serviceResult.result.datasourceInfo.description, null, 2) + "<br>";
            innerHTML += "distanceUnit:" + JSON.stringify(serviceResult.result.datasourceInfo.distanceUnit, null, 2) + "<br>";
            innerHTML += "engineType:" + JSON.stringify(serviceResult.result.datasourceInfo.engineType, null, 2) + "<br>";
            innerHTML += "name:" + JSON.stringify(serviceResult.result.datasourceInfo.name, null, 2) + "<br>";
            innerHTML += "prjCoordSys:" + "(...)" + "<br>";
        new mapboxgl.Popup({closeOnClick: false})
            .setLngLat([0,0])
            .setHTML(innerHTML + "</br>")
            .addTo(map);
    });

    }
</script>
</body>
</html>